import React, { Component } from 'react'

export default class CRefCom extends Component {
  //1. 创建容器对象
  input = React.createRef();
  div = React.createRef();

  show = () => {
    //3. 获取真实 DOM
    // console.log(this);
    let v = this.input.current.value;
    //设置 div 的文本
    this.div.current.innerHTML = v;
  }

  render() {
    return (
      <div>
        {/* 2. 设置元素 ref 的值 */}
        <input type="text" ref={this.input}  /><button onClick={this.show}>展示</button>
        <hr />
        <div ref={this.div} style={{width: 400, height: 300, border: 'solid 1px #345'}}>
        </div>
      </div>
    )
  }
}
